package com.qing.expert.modules.admin.controller;

import com.qing.expert.common.response.R;
import com.qing.expert.modules.admin.service.AdminService;
import com.qing.expert.modules.admin.vo.request.AdminSecretRequest;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    /**
     * 成为管理员
     */
    @PostMapping("/become")
    public R<Void> becomeAdmin(@Validated @RequestBody AdminSecretRequest request, HttpServletRequest httpRequest) {
        // 从请求中获取当前用户ID
        String userId = (String) httpRequest.getAttribute("userId");
        log.info("用户[{}]请求成为管理员", userId);

        adminService.becomeAdmin(userId, request.getSecretKey());
        return R.ok();
    }
}